<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>领钱管理</title>
    <#include "/include/resource.html"/>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "/include/header.html"/>
    <!-- Left side column. contains the logo and sidebar -->
    <#include "/include/main-sidebar.html"/>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                领钱列表
                <small>骑手待结账列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><i class="fa fa-dashboard"></i> 领钱列表</li>
                <li class="active">骑手待结账列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">领钱列表</h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body">
                            <form id="tableForm" method="post" class="form-horizontal" action="${base}/admin/riderAccount/list">
                                <input type="hidden" name="riderId" id="riderId" value="${riderId}">
                                <input type="hidden" name="status" value="${status}">
                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-md-2">
                                            <label for="inputEmail3" class="col-md-5 control-label">商户Name：</label>
                                            <div class="col-md-7" style="padding: 0px">
                                                <input type="text" class="form-control" value="${(merchartName)!''}" name="merchartName" id="inputEmail3" placeholder="商户Name">
                                            </div>
                                        </div>
                                        <div class="col-md-2" style="padding: 0px">
                                            <label class="col-md-5 control-label">起送日期：</label>
                                            <div class="input-group date col-md-7" >
                                                <div class="input-group-addon">
                                                    <i class="fa fa-calendar"></i>
                                                </div>
                                                <input type="text" class="form-control pull-right" name="dateRangeBe" value="${(dateRangeBe)!''}" id="datepicker">
                                            </div>
                                        </div>
                                        <div class="col-md-2" style="padding: 0px">
                                            <label class="col-md-2 control-label">--</label>
                                            <div class="input-group date col-md-7">
                                                <div class="input-group-addon">
                                                    <i class="fa fa-calendar"></i>
                                                </div>
                                                <input type="text" class="form-control pull-right" name="dateRangeEn" value="${(dateRangeEn)!''}"  id="datepicker_">
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <button type="button" onclick="HF.query('tableForm');" class="btn btn-primary">Query</button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                                <div class="row" style="float: right;padding-bottom: 10px;padding-right: 10px;">
                                    <#if status==4>
                                    <div class="col-md-8">
                                        <div class="dataTables_info" id="example2_info" role="status" aria-live="polite">
                                            总计: ¥${(riderAccount)!0.00}元
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                            <button type="button" onclick="getCheckBoxValues()" class="btn btn-primary">结算</button>
                                        </div>
                                    </#if>
                                    <#if status!=4>
                                        <div class="col-md-12">
                                            <div class="dataTables_info_" id="example2_info_" role="status" aria-live="polite">
                                                总计: ¥${(riderAccount)!0.00}元
                                            </div>
                                        </div>
                                    </#if>
                                </div>
                                <table class="table table-bordered">
                                    <tr>
                                        <th>
                                        <#if status==4>
                                            <input type="checkbox" id="selectAll" class="minimal" style="position: absolute; opacity: 0;">
                                        </#if>
                                            SequenceNo
                                        </th>
                                        <th>商户Name</th>
                                        <th>货物类型</th>
                                        <th>起始地址</th>
                                        <th>目的地址</th>
                                        <th>起送日期</th>
                                        <th>骑手姓名</th>
                                        <th>骑手联系方式</th>
                                        <th>完成日期</th>
                                        <th>订单金额</th>
                                        <th>订单Status</th>
                                    </tr>
                                    <#if list??&&list?size gt 0>
                                        <#list list as t>
                                            <tr>
                                                <td>
                                                    <#if status==4>
                                                        <input type="checkbox" class="minimal" name="toPay" value="${t.id}" id="toPay" style="position: absolute; opacity: 0;">
                                                    </#if>
                                                    ${t_index+1}
                                                </td>
                                                <td>${(t.merchartName)!""}</td>
                                                <td>${(t.goodsType)!""}</td>
                                                <td>${(t.start)!""}</td>
                                                <td>${(t.end)!""}</td>
                                                <td>${nav.getDate((t.startTime)!0)}</td>
                                                <td>${(t.riderName)!""}</td>
                                                <td>${(t.riderPhone)!""}</td>
                                                <td>${nav.getDate((t.cancelDate)!0)}</td>
                                                <td>${(t.riderAmount)!""}</td>
                                                <td>${nav.getOrderStatus((t.status)!"")}</td>
                                            </tr>
                                        </#list>
                                        <#else>
                                        <tr>
                                            <td colspan="11" align="center">no record!</td>
                                        </tr>
                                    </#if>
                                </table>
                        </div>
                        <!-- /.box-body -->
                    <#if status==5>
                        <@p.pager pageNo=pageNo pageSize=pageSize totalCount=totalCount />
                    </#if>
                    </div>
                    <!-- /.box -->
                </div>
            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- 弹出窗口 -->
    <div class="modal fade" id="myModal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">Details</h4>
                </div>
                <div class="modal-body">
                    <p id="dialogInfo"></p>
                    <div class="form-group">
                        <label>Note</label>
                        <textarea class="form-control" id="memo" rows="3" placeholder="请输入Note信息.."></textarea>
                        <input type="hidden" id="orderIds">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" onclick="updateOrderStatus()">确定</button>
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 2.4.0
        </div>
        <strong>Copyright &copy; 2014-2016 <a href="https://adminlte.io">Almsaeed Studio</a>.</strong> All rights
        reserved.
    </footer>
    <div class="control-sidebar-bg"></div>
</div>
<#include "/include/js_footer.html"/>
<script type="application/javascript">
    $(function () {

        $.fn.datepicker.defaults.format = "yyyy-mm-dd";
        $('#datepicker').datepicker({
            autoclose: true
        })

        $('#datepicker_').datepicker({
            autoclose: true
        })
        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass   : 'iradio_minimal-blue'
        })
        //全选
        $('#selectAll').on('ifChecked', function(event){
            $('input').iCheck('check');
        });
        $('#selectAll').on('ifUnchecked', function(event){
            $('input').iCheck('uncheck');
        });
    })
    function getCheckBoxValues() {

        var checkBoxArr = [];
        $('input[name="toPay"]:checked').each(function() {
            checkBoxArr.push($(this).val());
        });
        if(checkBoxArr.length<=0){

            bootbox.alert("请选择需要结算的订单!");
            return false;
        }
        //获取汇钱总额
        $.ajax({
            type: "POST",
            url: "${base}/admin/rider_orderAccount/account?ids="+checkBoxArr.toString(),
            dataType: "json",
            success: function(data){

                $("#orderIds").val(checkBoxArr.toString());
                if(typeof(data)!='undefined'){

                    $("#dialogInfo").html("本次支付金额:"+ data);
                    $('#myModal').modal('show');
                }
            },
            error:function(){
                alert("系统未知异常!");
            }
        });
    }
    function updateOrderStatus(){
        var ids = $("#orderIds").val();
        var memo = $("#memo").val();
        var riderId = $("#riderId").val();
        //获取汇钱总额
        $.ajax({
            type: "POST",
            url: "${base}/admin/rider_orderAccount/update?ids="+ids+"&memo="+memo+"&riderId="+riderId,
            dataType: "json",
            success: function(data){

                window.location = '${base}/admin/riderAccount/list?riderId='+riderId+"&status=4";
            },
            error:function(){
                alert("系统未知异常!");
            }
        });

    }
</script>
</body>
</html>
